<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        fieldset{
            width: 500px;
            margin: 150px auto;
            border: 0px;
            padding: 30px;
        }
    </style>
</head>
<body>

<div id="app">

    <fieldset>
        <span class="label label-warning">{{msg}}</span>
        <el-form :model="info" status-icon :rules="rules" ref="info" label-width="100px" class="demo-ruleForm">
            <el-form-item label="部门名称" prop="bname">
                <el-input v-model="info.bname" placeholder="不可添加重复部门"></el-input>
            </el-form-item>


            <el-form-item>
                <el-button type="primary" @click="submitForm('info')">添 加</el-button>
                <el-button                @click="resetForm('info')">重 置</el-button>
            </el-form-item>
        </el-form>

    </fieldset>


</div>

<script>
    var haha=new Vue({
        el:"#app",
        data:{
            info:{},
            msg:"",
            rules: {
                bname: [
                    { required: true, message: '请输入部门名称', trigger: 'blur' }
                ]
            }
        },
        methods:{
            submitForm(formName) {
                haha.$refs[formName].validate((valid) => {
                    if (valid) {
                        $.post("/ssm/branch/add",haha.info,function (backData) {
                            if (backData.code==2){
                                haha.$notify.error({
                                    title: '温馨提示',
                                    message:backData.msg
                                });
                            }else if (backData.code==1){
                                window.location.href="/ssm/branchcontrol/branchmain.html";
                            }
                        });
                    }
                });
            },
            resetForm(formName) {
                haha.$refs[formName].resetFields();
            }
        }
    });
</script>

</body>
</html>